//
//  XTStatusToolBar.swift
//  MyBlog
//
//  Created by victor on 17/3/24.
//  Copyright © 2017年 victor. All rights reserved.
//

import UIKit

class XTStatusToolBar: UIView {

    var viewModel: XTStatusViewModel? {
        didSet {
            retweetedButton.setTitle(viewModel?.retweetedStr, for: .normal)
            commentButton.setTitle(viewModel?.commentStr, for: .normal)
            likeButton.setTitle(viewModel?.likeStr, for: .normal)   
        }
    }
    
    /// 转发
    fileprivate lazy var retweetedButton: UIButton = UIButton.cz_imageButton(
        "timeline_icon_retweet",
        backgroundImageName: "timeline_card_bottom_background")
    /// 评论
    fileprivate lazy var commentButton: UIButton = UIButton.cz_imageButton(
        "timeline_icon_comment",
        backgroundImageName: "timeline_card_bottom_background")
    /// 赞
    fileprivate lazy var likeButton: UIButton = UIButton.cz_imageButton(
        "timeline_icon_unlike",
        backgroundImageName: "timeline_card_bottom_background")
    /// 按钮分割线
    fileprivate lazy var leftLineImgView = UIImageView()
    fileprivate lazy var rightLineImgView = UIImageView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    fileprivate func setupUI() {
        retweetedButton.setTitle("转发", for: .normal)
        retweetedButton.titleLabel?.font = UIFont.systemFont(ofSize: 11)
        retweetedButton.setTitleColor(UIColor.black, for: .normal)
        retweetedButton.titleEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0)
        
        commentButton.setTitle("评论", for: .normal)
        commentButton.titleLabel?.font = UIFont.systemFont(ofSize: 11)
        commentButton.setTitleColor(UIColor.black, for: .normal)
        commentButton.titleEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0)
        
        likeButton.setTitle("赞", for: .normal)
        likeButton.titleLabel?.font = UIFont.systemFont(ofSize: 11)
        likeButton.setTitleColor(UIColor.black, for: .normal)
        likeButton.titleEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0)
        
        leftLineImgView.image = UIImage(named: "timeline_card_bottom_line")
        rightLineImgView.image = UIImage(named: "timeline_card_bottom_line")
        
        addSubview(retweetedButton)
        addSubview(commentButton)
        addSubview(likeButton)
        addSubview(leftLineImgView)
        addSubview(rightLineImgView)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        retweetedButton.snp.makeConstraints { (make) in
            make.top.equalTo(self.snp.top)
            make.left.equalTo(self.snp.left)
            make.height.equalTo(37)
            make.width.equalTo(UIScreen.main.bounds.width / 3)
        }
        
        commentButton.snp.makeConstraints { (make) in
            make.left.equalTo(retweetedButton.snp.right)
            make.centerY.equalTo(retweetedButton.snp.centerY)
            make.width.equalTo(retweetedButton.snp.width)
            make.height.equalTo(retweetedButton.snp.height)
        }
        
        likeButton.snp.makeConstraints { (make) in
            make.left.equalTo(commentButton.snp.right)
            make.centerY.equalTo(retweetedButton.snp.centerY)
            make.width.equalTo(retweetedButton.snp.width)
            make.height.equalTo(retweetedButton.snp.height)
        }
        
        leftLineImgView.snp.makeConstraints { (make) in
            make.left.equalTo(retweetedButton.snp.right).offset(-0.5)
            make.centerY.equalTo(retweetedButton.snp.centerY)
            make.width.equalTo(1)
            make.height.equalTo(20)
        }
        
        rightLineImgView.snp.makeConstraints { (make) in
            make.left.equalTo(commentButton.snp.right).offset(-0.5)
            make.centerY.equalTo(commentButton.snp.centerY)
            make.width.equalTo(1)
            make.height.equalTo(20)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
